<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0">
		<title>开具电子发票</title>
		<link href="css/index.css" rel="stylesheet" />
	</head>
	<body>
	<script type="text/javascript" src="js/jquery.min.js" ></script>
	<script type="text/javascript" src="js/oldPublic.js" ></script>
	<script src="js/code.js"></script>
	<script src="js/security.js"></script>
	<div class="wrapInvoice">
		<div class="wrapAdd">
		<div class="headTitle">
		<img onclick="goback()" src="./img/leftArrow.jpg" />
		<p>开具电子发票</p>
       	</div>
       	
		<div class="wrapdivList">
			<div class="divList">
				<div>
				<ul>
					<!--<li>
						<span class="chooseSpan"><img src="img/yuan.png"  /></span>
						<p class="pContent">
							<span class="spanTitle">市名卡充值</span>
							<span class="spanTime">2016年7月10日 12:00</span>
							<span class="spanNum">卡号:1000661668831000</span>
						</p>
						<span class="spanMoney">￥100</span> 
					</li>-->
				
				</ul>
				</div>
			</div>
		</div>
		<div class="divBottom">
			<span  class="spanChoose"><img src="img/yuan.png" /></span>
			<span class="spanChooseAll">全选</span>
			<span class="spanMoney">合计:￥0.00</span>
			<button class="nextBtn">下一步</button>
		</div>
	</div> 
	
		<div class="noRecord">
		<img src="img/noRecord.jpg" />
		<span>暂无历史记录哟！</span>
		</div>
<script>
	var login_name = sessionStorage.getItem('login_name');
	var telphone = sessionStorage.getItem('telphone');
	var orgcode = sessionStorage.getItem('orgcode');
				var dataList = '';
				$.ajax({
				type:"post",
				url:sessionStorage.getItem('ipconfig'),
				data:JSON.stringify({data:encryptByDESModeEBC(JSON.stringify({"tag": "9103",'login_name': login_name, 'telphone':telphone, 'status': '0','orgcode':orgcode }))}),
				contentType: "application/json;charset=utf-8",
				success:function(data){
					console.log(data);
					var str = '';
					if(data.result=='00'){
						dataList = data;
						if(data.card_info.length==0){
							$('.noRecord').show();
							return;
						}
						for(var i=0;i<data.card_info.length;i++){
							str+='<li>'+
								'<span onclick="chooseCard(this)" class="chooseSpan"><img class="chooseImg" src="img/yuan.png" /></span>'+
						        '<p class="pContent">'+
								'<span class="spanTitle">'+cardType(data.card_info[i].inntype)+'</span>'+
								'<span class="spanTime">'+datafrom(data.card_info[i].txndate,data.card_info[i].txntime)+'</span>'+
								'<span class="spanNum">卡号:'+data.card_info[i].accno+'</span>'+
						'</p>'+
						'<span class="spanMoney">￥'+data.card_info[i].txnamt/100||''+'</span>'+
						'</li>'
						}
					$('ul').html(str);
					}
					console.log(dataList);
				}
			});
	
	
	function chooseCard(a){
	if($(a).find('img').attr('src')=='img/yuan.png'){
		$(a).find('img').attr('src','img/dui.png');
	}else{
		$(a).find('img').attr('src','img/yuan.png');
	}
	$('.divBottom .spanMoney').html('合计:￥'+allPrice());
	}
	
	$('.spanChoose').click(function(){
		if($(this).find('img').attr('src')=='img/yuan.png'){
			$(this).find('img').attr('src','img/dui.png');
			$('.chooseImg').attr('src','img/dui.png');
		}else{
			$(this).find('img').attr('src','img/yuan.png');
			$('.chooseImg').attr('src','img/yuan.png');
		}
		$('.divBottom .spanMoney').html('合计:￥'+allPrice());
	})
	
	function allPrice(){
		var allPrice = 0;
		for(var i=0;i<dataList.card_info.length;i++){
			if($('.chooseImg').eq(i).attr('src')=='img/dui.png'){
				var itemTxnamt = dataList.card_info[i].txnamt/100;
				allPrice+=itemTxnamt;
			}
		}
		allPrice = allPrice.toFixed(2);
		return allPrice;
	}
	
	$('.nextBtn').click(function(){
		var allPriceMoney = allPrice();
		var arr = [];
		for(var i=0;i<dataList.card_info.length;i++){
			if($('.chooseImg').eq(i).attr('src')=='img/dui.png'){
				arr.push(dataList.card_info[i]);
			}
		}
		arr = JSON.stringify(arr);
		console.log(arr);
		window.location.href = './inputInfo.html?arrlist='+arr+'&allPrice='+allPriceMoney;
	})
	
	function cardType(type){
		var text='';
		if(type=='5163'){
			text='充值交易'
		}else if(type=='2063'){
			text='售卡交易'
		}
		return text;
	}
	
	function datafrom(year,day){
		var yearData;
		var dayData;
		yearData = year.substring(0,4)+'年'+year.substring(4,6)+'月'+year.substring(6,8)+'日';
		dayData = year.substring(0,2)+':'+year.substring(2,4);
		return yearData+' '+dayData;
	}
	
</script>

</body>
</html>
